<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Kugou
 *
 * @author dragon.hu add @2016.2.24
 */
require_once 'BaseChannel.php';

//酷狗
class Kugou implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="9fa5bd80115a707bd7949113fb2c9e55"; //key
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //秘钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("kugou", $_REQUEST);
		
		$orderid = $_REQUEST['orderid'];
		$outorderid = $_REQUEST['outorderid'];
		$amount = $_REQUEST['amount'];
		$username = $_REQUEST['username'];
		$status = $_REQUEST['status'];
		$time = $_REQUEST['time'];
		$ext1 = $_REQUEST['ext1'];
		$ext2 = $_REQUEST['ext2'];
		$sign = $_REQUEST['sign'];
		
		$mysign = $orderid.$outorderid.$amount.$username.$status.$time.$ext1.$ext2.$paymentKey;
		
		if($sign == md5($mysign))
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($status != 1)
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $amount, $ext1, "kugou", $platform,$outorderid))
			{
				$ret="FAIL";
				$orderLog->log("kugou",array("order"=>$ext1,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="SUCCESS";
				$orderLog->log("kugou",array("order"=>$ext1,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} 
		else 
		{
			//"$sig验证失败"
			$ret="FAIL";
			$orderLog->log("kugou","  order:$ext1  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}